package com.yanqu.road.dao.impl.servercenter;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.servercenter.PackageMjbContent;
import com.yanqu.road.entity.servercenter.PackageVersion;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 整包版本信息
 */
public class PackageVersionDaoImpl extends TempDao {

	public List<PackageVersion> getPackageVersionList() {
		ResultSet rs = null;
		CallableStatement call = null;
		String sql = "select * from t_s_package_version";
		List<PackageVersion> dataList = new ArrayList<>();
		try {
			getDb().setConnName(DbNameStrategy.getServerDb());
			call = getDb().getConnection().prepareCall(sql);
			rs = call.executeQuery();
			while (rs.next()) {
				PackageVersion data = new PackageVersion();
				data.setPackageMark(rs.getString("packageMark"));
				data.setPackageVersion(rs.getString("packageVersion"));
				data.setRecommendVersion(rs.getBoolean("isRecommendVersion"));
				data.setWhiteRecommendVersion(rs.getBoolean("isWhiteRecommendVersion"));
				data.setUpdateLevel(rs.getInt("updateLevel"));
				data.setUpdateMethod(rs.getInt("updateMethod"));
				data.setDownloadUrl(rs.getString("downloadUrl"));
				data.setDelete(rs.getBoolean("isDelete"));
				data.setWhiteUpdateLevel(rs.getInt("whiteUpdateLevel"));
				data.setWhiteUpdateMethod(rs.getInt("whiteUpdateMethod"));
				data.setForwardRecommendVersion(rs.getBoolean("isForwardRecommendVersion"));
				data.setForwardUpdateLevel(rs.getInt("forwardUpdateLevel"));
				data.setForwardUpdateMethod(rs.getInt("forwardUpdateMethod"));
				dataList.add(data);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			getDb().closeConnection(call, rs);
		}
		return dataList;
	}

	public List<PackageMjbContent> getPackageContentList() {
		ResultSet rs = null;
		CallableStatement call = null;
		String sql = "select * from t_s_package_mjb_content";
		List<PackageMjbContent> dataList = new ArrayList<>();
		try {
			getDb().setConnName(DbNameStrategy.getServerDb());
			call = getDb().getConnection().prepareCall(sql);
			rs = call.executeQuery();
			while (rs.next()) {
				PackageMjbContent data = new PackageMjbContent();
				data.setPackageMark(rs.getString("packageMark"));
				data.setReview(rs.getBoolean("isTiShen"));
				data.setContent(rs.getString("content"));
				dataList.add(data);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			getDb().closeConnection(call, rs);
		}
		return dataList;
	}
}
